package com.gzhryc.common.data.dto;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.gzhryc.common.config.I18nTools;

public class ListResult<T> extends BaseResponse<ListResult.Body<T>> {

	private static final long serialVersionUID = 1L;

	public ListResult(Integer code) {
		this.code = code;
		this.body = new ListResult.Body<>();
	}

	public ListResult(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
		this.body = new ListResult.Body<>();
	}

	public Integer getCode() {
		return this.code;
	}

	public String getMsg() {
		if ((this.body.getData() == null || this.body.getData().size() == 0) && StringUtils.isBlank(this.msg)) {
			I18nTools.I18n i18n = I18nTools.getCurrentI18n();
			if (i18n != null) {
				this.msg = i18n.get("notData", null);
			}
		}
		return this.msg;
	}

	public static class Body<T> {

		private Long total;
		private Integer limit;
		private Integer page;
		private List<T> data;

		public Long getTotal() {
			if ((total == null || total == 0) && data != null && data.size() > 0) {
				total = (long) data.size();
			}
			return total;
		}

		public void setTotal(Long total) {
			this.total = total;
		}

		public Integer getLimit() {
			return limit;
		}

		public void setLimit(Integer limit) {
			this.limit = limit;
		}

		public Integer getPage() {
			return page;
		}

		public void setPage(Integer page) {
			this.page = page;
		}

		public List<T> getData() {
			return data;
		}

		public void setData(List<T> data) {
			this.data = data;
		}
	}
}
